package com.infoland.afanmall.base.util;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ActivityOptions;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.BlurMaskFilter;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.NotificationCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.InputType;
import android.text.Layout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.TextView;

import com.alibaba.fastjson.JSONObject;
import com.blankj.utilcode.util.SizeUtils;
//import com.bumptech.glide.Glide;
import com.blankj.utilcode.util.ToastUtils;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.transition.Transition;
import com.infoland.afanmall.R;

import com.infoland.afanmall.base.activity.GlideApp;
import com.infoland.afanmall.base.dialog.OpenIsOk_1_Dialog;
import com.infoland.afanmall.base.dialog.OpenIsOk_2_Dialog;
import com.infoland.afanmall.base.dialog.ShareDialogFragment;
import com.infoland.afanmall.base.util.transition.EasyTransition;
import com.infoland.afanmall.base.util.transition.EasyTransitionOptions;
import com.infoland.afanmall.base.view.video.MyJiaoZiVideo;
import com.infoland.afanmall.model.guiGe.dialog.GuiGeDialogFragment;
import com.infoland.afanmall.model.order.activity.OrderDownActivity;
import com.infoland.afanmall.model.youXuan.activity.GoodInfoActivity;
import com.lzy.okgo.OkGo;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.vondear.rxtools.RxDataTool;
import com.vondear.rxtools.RxDeviceTool;
import com.vondear.rxtools.RxEncodeTool;
import com.vondear.rxtools.RxFileTool;
import com.vondear.rxtools.RxNetTool;
import com.vondear.rxtools.RxTextTool;
import com.vondear.rxtools.interfaces.OnRequestListener;
import com.vondear.rxtools.module.wechat.pay.WechatPayTools;

import org.greenrobot.eventbus.EventBus;

import java.io.Closeable;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.GregorianCalendar;
import java.util.Hashtable;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;

import cn.jzvd.JZVideoPlayerStandard;

import static android.content.Context.NOTIFICATION_SERVICE;
import static com.blankj.utilcode.util.ActivityUtils.startActivity;

public class ToolsKit {

    private ToolsKit() {
    }

    //设置图片
    public static void setImg(View v, String url, ImageView view) {
        if (view != null && v != null && url != null) {
            GlideApp.with(v).load(url).error(R.mipmap.lymr).into(view);
        }
    }

    //写给 GoodinfoActivity的 RecyclerView 使用
    public static void setImgOverride(View v, String url, ImageView view) {
        if (view != null && v != null && url != null) {
            GlideApp.with(v).asDrawable().
                    load(url).skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.ALL).
                    placeholder(R.mipmap.lymr).error(R.mipmap.lymr).thumbnail(1f)
                    .override(RxDeviceTool.getScreenWidth(CacheKit.APP_CONTEXT),
                            RxDeviceTool.getScreenHeight(CacheKit.APP_CONTEXT)).into(view);
        }
    }

    //写给 GoodinfoActivity的 RecyclerView 使用
    public static void setImgListRecycler(Activity v, String url, ImageView view) {
        if (view != null && v != null && url != null) {
            GlideApp.with(v).asDrawable().
                    load(url).skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.ALL).
                    placeholder(R.mipmap.lymr).error(R.mipmap.lymr).thumbnail(1f)
                    .override(RxDeviceTool.getScreenWidth(CacheKit.APP_CONTEXT),
                            RxDeviceTool.getScreenHeight(CacheKit.APP_CONTEXT)).into(view);
        }
    }

    //设置图片
    public static void setImgActivity(Activity v, String url, ImageView view) {
        if (view != null && v != null && url != null) {
            GlideApp.with(v).asDrawable().
                    load(url).skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.ALL).
                    placeholder(R.mipmap.lymr).error(R.mipmap.lymr).into(view);
        }
    }

    //设置图片
    public static void setImgActivity(Activity v, int resId, ImageView view) {
        if (view != null && v != null) {
            GlideApp.with(v).asDrawable().
                    load(resId).skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.ALL).
                    placeholder(R.mipmap.lymr).error(R.mipmap.lymr).into(view);
        }
    }

    //设置图片
    public static void setImgFragment(Fragment v, String url, ImageView view) {
        if (view != null && v != null && url != null) {
            GlideApp.with(v).asDrawable().
                    load(url).skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.ALL).
                    placeholder(R.mipmap.lymr).error(R.mipmap.lymr).into(view);
        }
    }

    //设置图片
    public static void setImgFragment(Fragment v, int resId, ImageView view) {
        if (view != null && v != null) {
            GlideApp.with(v).asDrawable().
                    load(resId).skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.ALL).
                    placeholder(R.mipmap.lymr).error(R.mipmap.lymr).into(view);
        }
    }

    //设置图片
    public static void setImgView(View v, String url, ImageView view) {
        if (view != null && v != null && url != null) {
            GlideApp.with(v).asDrawable().
                    load(url).skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.ALL).
                    placeholder(R.mipmap.lymr).error(R.mipmap.lymr).into(view);
        }
    }

    //设置图片
    public static void setImgView(View v, int resId, ImageView view) {
        if (view != null && v != null) {
            GlideApp.with(v).asDrawable().
                    load(resId).skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.ALL).
                    placeholder(R.mipmap.lymr).error(R.mipmap.lymr).into(view);
        }
    }

    //设置图片
    public static void setImgView(String url, ImageView view) {
        if (view != null && url != null) {
            GlideApp.with(view).asDrawable().
                    load(url).skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.ALL).
                    placeholder(R.mipmap.lymr).error(R.mipmap.lymr).into(view);
        }
    }

    //设置图片
    public static void setImgView(int resId, ImageView view) {
        if (view != null) {
            GlideApp.with(view).asDrawable().
                    load(resId).skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.ALL).
                    placeholder(R.mipmap.lymr).error(R.mipmap.lymr).into(view);
        }
    }

    //设置Background*/
    public static void setBackImg(String url, View view) {

        GlideApp.with(CacheKit.APP_CONTEXT).load(url).skipMemoryCache(true)
                .diskCacheStrategy(DiskCacheStrategy.ALL).into(new SimpleTarget<Drawable>() {
            @Override
            public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
                if (view != null) {
                    view.setBackground(resource);
                }
            }
        });
    }

    //设置Background
    public static void setBackImg(int resId, View view) {
        if (view != null) {
            GlideApp.with(CacheKit.APP_CONTEXT).load(resId).skipMemoryCache(true).
                    diskCacheStrategy(DiskCacheStrategy.ALL).into(new SimpleTarget<Drawable>() {
                @Override
                public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
                    if (view != null) {
                        view.setBackground(resource);
                    }
                }
            });
        }
    }

    //加载圆形图片
    public static void setImgYuanToUrl(String url, View view) {
        if (view != null && url != null) {
            Glide.with(CacheKit.APP_CONTEXT).load(url).apply(RequestOptions.
                    bitmapTransform(new CircleCrop())).into((ImageView) view);
        }
    }

    //加载圆形图片
    public static void setImgYuanToResource(int id, View view) {
        if (view != null) {
            Glide.with(CacheKit.APP_CONTEXT).load(id).apply(RequestOptions.bitmapTransform(new CircleCrop()))
                    .into((ImageView) view);
        }
    }

    public static void setTypeNumber(EditText editText) {
        editText.setInputType(EditorInfo.TYPE_CLASS_PHONE);
    }

    public static void setTypePassWord(EditText editText) {
        editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
    }

    private static final String DES_Algorithm = "DES";
    private static final String TripleDES_Algorithm = "DESede";
    private static final String AES_Algorithm = "AES";
    public static String DES_Transformation = "DES/ECB/NoPadding";
    public static String TripleDES_Transformation = "DESede/ECB/NoPadding";
    public static String AES_Transformation = "AES/ECB/NoPadding";

    public static String encryptMD2ToString(String data) {
        return encryptMD2ToString(data.getBytes());
    }

    public static String encryptMD2ToString(byte[] data) {
        return RxDataTool.bytes2HexString(encryptMD2(data));
    }

    public static byte[] encryptMD2(byte[] data) {
        return encryptAlgorithm(data, "MD2");
    }

    public static String encryptMD5ToString(String data) {
        return encryptMD5ToString(data.getBytes());
    }

    public static String encryptMD5ToString(String data, String salt) {
        return RxDataTool.bytes2HexString(encryptMD5((data + salt).getBytes()));
    }

    public static String encryptMD5ToString(byte[] data) {
        return RxDataTool.bytes2HexString(encryptMD5(data));
    }

    public static String encryptMD5ToString(byte[] data, byte[] salt) {
        byte[] dataSalt = new byte[data.length + salt.length];
        System.arraycopy(data, 0, dataSalt, 0, data.length);
        System.arraycopy(salt, 0, dataSalt, data.length, salt.length);
        return RxDataTool.bytes2HexString(encryptMD5(dataSalt));
    }

    public static byte[] encryptMD5(byte[] data) {
        return encryptAlgorithm(data, "MD5");
    }

    public static String encryptMD5File2String(String filePath) {
        return encryptMD5File2String(new File(filePath));
    }

    public static byte[] encryptMD5File(String filePath) {
        return encryptMD5File(new File(filePath));
    }

    public static String encryptMD5File2String(File file) {
        return encryptMD5File(file) != null ? RxDataTool.bytes2HexString(encryptMD5File(file)) : "";
    }

    public static byte[] encryptMD5File(File file) {
        FileInputStream fis = null;

        try {
            fis = new FileInputStream(file);
            FileChannel channel = fis.getChannel();
            MappedByteBuffer buffer = channel.map(FileChannel.MapMode.READ_ONLY, 0L, file.length());
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(buffer);
            byte[] var5 = md.digest();
            return var5;
        } catch (IOException | NoSuchAlgorithmException var9) {
            var9.printStackTrace();
        } finally {
            RxFileTool.closeIO(new Closeable[]{fis});
        }

        return null;
    }

    public static String getSHA1String(String data) {
        return getSHA1String(data.getBytes());
    }

    public static String getSHA1String(byte[] data) {
        return RxDataTool.bytes2HexString(encryptSHA1(data));
    }

    public static byte[] encryptSHA1(byte[] data) {
        return encryptAlgorithm(data, "SHA-1");
    }

    public static String encryptSHA224ToString(String data) {
        return encryptSHA224ToString(data.getBytes());
    }

    public static String encryptSHA224ToString(byte[] data) {
        return RxDataTool.bytes2HexString(encryptSHA224(data));
    }

    public static byte[] encryptSHA224(byte[] data) {
        return encryptAlgorithm(data, "SHA-224");
    }

    public static String encryptSHA256ToString(String data) {
        return encryptSHA256ToString(data.getBytes());
    }

    public static String encryptSHA256ToString(byte[] data) {
        return RxDataTool.bytes2HexString(encryptSHA256(data));
    }

    public static byte[] encryptSHA256(byte[] data) {
        return encryptAlgorithm(data, "SHA-256");
    }

    public static String encryptSHA384ToString(String data) {
        return encryptSHA384ToString(data.getBytes());
    }

    public static String encryptSHA384ToString(byte[] data) {
        return RxDataTool.bytes2HexString(encryptSHA384(data));
    }

    public static byte[] encryptSHA384(byte[] data) {
        return encryptAlgorithm(data, "SHA-384");
    }

    public static String encryptSHA512ToString(String data) {
        return encryptSHA512ToString(data.getBytes());
    }

    public static String encryptSHA512ToString(byte[] data) {
        return RxDataTool.bytes2HexString(encryptSHA512(data));
    }

    public static byte[] encryptSHA512(byte[] data) {
        return encryptAlgorithm(data, "SHA-512");
    }

    private static byte[] encryptAlgorithm(byte[] data, String algorithm) {
        try {
            MessageDigest md = MessageDigest.getInstance(algorithm);
            md.update(data);
            return md.digest();
        } catch (NoSuchAlgorithmException var3) {
            var3.printStackTrace();
            return new byte[0];
        }
    }

    public static byte[] DESTemplet(byte[] data, byte[] key, String algorithm, String transformation, boolean isEncrypt) {
        try {
            SecretKeySpec keySpec = new SecretKeySpec(key, algorithm);
            Cipher cipher = Cipher.getInstance(transformation);
            SecureRandom random = new SecureRandom();
            cipher.init(isEncrypt ? 1 : 2, keySpec, random);
            return cipher.doFinal(data);
        } catch (Throwable var8) {
            var8.printStackTrace();
            return null;
        }
    }

    public static byte[] encryptDES2Base64(byte[] data, byte[] key) {
        return RxEncodeTool.base64Encode(encryptDES(data, key));
    }

    public static String encryptDES2HexString(byte[] data, byte[] key) {
        return RxDataTool.bytes2HexString(encryptDES(data, key));
    }

    public static byte[] encryptDES(byte[] data, byte[] key) {
        return DESTemplet(data, key, "DES", DES_Transformation, true);
    }

    public static byte[] decryptBase64DES(byte[] data, byte[] key) {
        return decryptDES(RxEncodeTool.base64Decode(data), key);
    }

    public static byte[] decryptHexStringDES(String data, byte[] key) {
        return decryptDES(RxDataTool.hexString2Bytes(data), key);
    }

    public static byte[] decryptDES(byte[] data, byte[] key) {
        return DESTemplet(data, key, "DES", DES_Transformation, false);
    }

    public static byte[] encrypt3DES2Base64(byte[] data, byte[] key) {
        return RxEncodeTool.base64Encode(encrypt3DES(data, key));
    }

    public static String encrypt3DES2HexString(byte[] data, byte[] key) {
        return RxDataTool.bytes2HexString(encrypt3DES(data, key));
    }

    public static byte[] encrypt3DES(byte[] data, byte[] key) {
        return DESTemplet(data, key, "DESede", TripleDES_Transformation, true);
    }

    public static byte[] decryptBase64_3DES(byte[] data, byte[] key) {
        return decrypt3DES(RxEncodeTool.base64Decode(data), key);
    }

    public static byte[] decryptHexString3DES(String data, byte[] key) {
        return decrypt3DES(RxDataTool.hexString2Bytes(data), key);
    }

    public static byte[] decrypt3DES(byte[] data, byte[] key) {
        return DESTemplet(data, key, "DESede", TripleDES_Transformation, false);
    }

    public static byte[] encryptAES2Base64(byte[] data, byte[] key) {
        return RxEncodeTool.base64Encode(encryptAES(data, key));
    }

    public static String encryptAES2HexString(byte[] data, byte[] key) {
        return RxDataTool.bytes2HexString(encryptAES(data, key));
    }

    public static byte[] encryptAES(byte[] data, byte[] key) {
        return DESTemplet(data, key, "AES", AES_Transformation, true);
    }

    public static byte[] decryptBase64AES(byte[] data, byte[] key) {
        return decryptAES(RxEncodeTool.base64Decode(data), key);
    }

    public static byte[] decryptHexStringAES(String data, byte[] key) {
        return decryptAES(RxDataTool.hexString2Bytes(data), key);
    }

    public static byte[] decryptAES(byte[] data, byte[] key) {
        return DESTemplet(data, key, "AES", AES_Transformation, false);
    }


    public static boolean isPhone(String mobiles) {
        Pattern p = Pattern.compile("^(13[0-9]|15[012356789]|17[03678]|18[0-9]|14[57])[0-9]{8}$");
        Matcher m = p.matcher(mobiles);
        return m.matches();
    }

    public static boolean isBankCard(String cardNo) {
        Pattern p = Pattern.compile("^\\d{16,19}$|^\\d{6}[- ]\\d{10,13}$|^\\d{4}[- ]\\d{4}[- ]\\d{4}[- ]\\d{4,7}$");
        Matcher m = p.matcher(cardNo);
        return m.matches();
    }

    public static boolean validateIdCard(String idCard) {
        String regIdCard = "^(^[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}$)|(^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])((\\d{4})|\\d{3}[Xx])$)$";
        Pattern p = Pattern.compile(regIdCard);
        return p.matcher(idCard).matches();
    }

    public static boolean isMobileSimple(String string) {
        return isMatch("^[1]\\d{10}$", string);
    }

    public static boolean isMobileExact(String string) {
        return isMatch("^((13[0-9])|(14[5,7])|(15[0-3,5-9])|(17[0,3,5-8])|(18[0-9])|(147))\\d{8}$", string);
    }

    public static boolean isTel(String string) {
        return isMatch("^0\\d{2,3}[- ]?\\d{7,8}", string);
    }

    public static boolean isIDCard15(String string) {
        return isMatch("^[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}$", string);
    }

    public static boolean isIDCard18(String string) {
        return isMatch("^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([0-9Xx])$", string);
    }

    public static boolean isIDCard(String string) {
        return isMatch("(^[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}$|^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([0-9]|x|X)$)", string);
    }

    @SuppressLint("WrongConstant")
    public static String IDCardValidate(String IDStr) throws ParseException {
        String errorInfo = "";
        String[] ValCodeArr = new String[]{"1", "0", "x", "9", "8", "7", "6", "5", "4", "3", "2"};
        String[] Wi = new String[]{"7", "9", "10", "5", "8", "4", "2", "1", "6", "3", "7", "9", "10", "5", "8", "4", "2"};
        String Ai = "";
        if (IDStr.length() != 15 && IDStr.length() != 18) {
            errorInfo = "身份证号码长度应该为15位或18位。";
            return errorInfo;
        } else {
            if (IDStr.length() == 18) {
                Ai = IDStr.substring(0, 17);
            } else if (IDStr.length() == 15) {
                Ai = IDStr.substring(0, 6) + "19" + IDStr.substring(6, 15);
            }

            if (!isNumeric(Ai)) {
                errorInfo = "身份证15位号码都应为数字 ; 18位号码除最后一位外，都应为数字。";
                return errorInfo;
            } else {
                String strYear = Ai.substring(6, 10);
                String strMonth = Ai.substring(10, 12);
                String strDay = Ai.substring(12, 14);
                if (!isDate(strYear + "-" + strMonth + "-" + strDay)) {
                    errorInfo = "身份证生日无效。";
                    return errorInfo;
                } else {
                    GregorianCalendar gc = new GregorianCalendar();
                    SimpleDateFormat s = new SimpleDateFormat("yyyy-MM-dd");

                    try {
                        if (gc.get(1) - Integer.parseInt(strYear) > 150 || gc.getTime().getTime() - s.parse(strYear + "-" + strMonth + "-" + strDay).getTime() < 0L) {
                            errorInfo = "身份证生日不在有效范围。";
                            return errorInfo;
                        }
                    } catch (NumberFormatException var14) {
                        var14.printStackTrace();
                    } catch (ParseException var15) {
                        var15.printStackTrace();
                    }

                    if (Integer.parseInt(strMonth) <= 12 && Integer.parseInt(strMonth) != 0) {
                        if (Integer.parseInt(strDay) <= 31 && Integer.parseInt(strDay) != 0) {
                            Hashtable h = GetAreaCode();
                            if (h.get(Ai.substring(0, 2)) == null) {
                                errorInfo = "身份证地区编码错误。";
                                return errorInfo;
                            } else {
                                int TotalmulAiWi = 0;

                                int modValue;
                                for (modValue = 0; modValue < 17; ++modValue) {
                                    TotalmulAiWi += Integer.parseInt(String.valueOf(Ai.charAt(modValue))) * Integer.parseInt(Wi[modValue]);
                                }

                                modValue = TotalmulAiWi % 11;
                                String strVerifyCode = ValCodeArr[modValue];
                                Ai = Ai + strVerifyCode;
                                if (IDStr.length() == 18) {
                                    if (!Ai.equals(IDStr)) {
                                        errorInfo = "身份证无效，不是合法的身份证号码";
                                        return errorInfo;
                                    } else {
                                        return "有效";
                                    }
                                } else {
                                    return "有效";
                                }
                            }
                        } else {
                            errorInfo = "身份证日期无效";
                            return errorInfo;
                        }
                    } else {
                        errorInfo = "身份证月份无效";
                        return errorInfo;
                    }
                }
            }
        }
    }

    private static Hashtable GetAreaCode() {
        Hashtable hashtable = new Hashtable();
        hashtable.put("11", "北京");
        hashtable.put("12", "天津");
        hashtable.put("13", "河北");
        hashtable.put("14", "山西");
        hashtable.put("15", "内蒙古");
        hashtable.put("21", "辽宁");
        hashtable.put("22", "吉林");
        hashtable.put("23", "黑龙江");
        hashtable.put("31", "上海");
        hashtable.put("32", "江苏");
        hashtable.put("33", "浙江");
        hashtable.put("34", "安徽");
        hashtable.put("35", "福建");
        hashtable.put("36", "江西");
        hashtable.put("37", "山东");
        hashtable.put("41", "河南");
        hashtable.put("42", "湖北");
        hashtable.put("43", "湖南");
        hashtable.put("44", "广东");
        hashtable.put("45", "广西");
        hashtable.put("46", "海南");
        hashtable.put("50", "重庆");
        hashtable.put("51", "四川");
        hashtable.put("52", "贵州");
        hashtable.put("53", "云南");
        hashtable.put("54", "西藏");
        hashtable.put("61", "陕西");
        hashtable.put("62", "甘肃");
        hashtable.put("63", "青海");
        hashtable.put("64", "宁夏");
        hashtable.put("65", "新疆");
        hashtable.put("71", "台湾");
        hashtable.put("81", "香港");
        hashtable.put("82", "澳门");
        hashtable.put("91", "国外");
        return hashtable;
    }

    private static boolean isNumeric(String str) {
        Pattern pattern = Pattern.compile("[0-9]*");
        Matcher isNum = pattern.matcher(str);
        return isNum.matches();
    }

    public static boolean isEmail(String string) {
        return isMatch("^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$", string);
    }

    public static boolean isURL(String string) {
        return isMatch("http(s)?://([\\w-]+\\.)+[\\w-]+(/[\\w-./?%&=]*)?", string);
    }

    public static boolean isChz(String string) {
        return isMatch("^[\\u4e00-\\u9fa5]+$", string);
    }

    public static boolean isUsername(String string) {
        return isMatch("^[\\w\\u4e00-\\u9fa5]{6,20}(?<!_)$", string);
    }

    public static boolean isDate(String string) {
        return isMatch("^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$", string);
    }

    public static boolean isIP(String string) {
        return isMatch("((2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)", string);
    }

    public static boolean isMatch(String regex, String string) {
        return !RxDataTool.isNullString(string) && Pattern.matches(regex, string);
    }

    public static boolean checkPhone(String phone) {
        String regex = "(\\+\\d+)?(\\d{3,4}\\-?)?\\d{7,8}$";
        return Pattern.matches(regex, phone);
    }

    public static boolean checkDigit(String digit) {
        String regex = "\\-?[1-9]\\d+";
        return Pattern.matches(regex, digit);
    }

    public static boolean checkDecimals(String decimals) {
        String regex = "\\-?[1-9]\\d+(\\.\\d+)?";
        return Pattern.matches(regex, decimals);
    }

    public static boolean checkBlankSpace(String blankSpace) {
        String regex = "\\s+";
        return Pattern.matches(regex, blankSpace);
    }

    public static boolean checkBirthday(String birthday) {
        String regex = "[1-9]{4}([-./])\\d{1,2}\\1\\d{1,2}";
        return Pattern.matches(regex, birthday);
    }

    public static boolean checkPostcode(String postcode) {
        String regex = "[1-9]\\d{5}";
        return Pattern.matches(regex, postcode);
    }

    public static boolean isYzM(String yam) {
        if (yam.length() < 4) {
            return false;
        }
        return true;
    }

    public static boolean isPassword(String password) {
        if (password.length() < 6 || password.length() > 16) {
            return false;
        }
        return true;
    }


    /***获取 View 宽度 和 高度*/
    public static int[] getVewSize(View view) {
        return SizeUtils.measureView(view);
    }

    /***获取 View 宽度*/
    public static int getViewWidth(View view) {
        return SizeUtils.getMeasuredWidth(view);
    }

    /***获取 View 高度*/
    public static int getViewHeight(View view) {
        return SizeUtils.getMeasuredHeight(view);
    }

    /***增加 View Margin*/
    public static void addMargin(View view, int marLeft, int marTop, int marRight, int marBottom) {
        ViewGroup.LayoutParams lp = view.getLayoutParams();
        if (lp instanceof ViewGroup.MarginLayoutParams) {
            ((ViewGroup.MarginLayoutParams) lp).leftMargin += marLeft;//增高
            ((ViewGroup.MarginLayoutParams) lp).topMargin += marTop;//增高
            ((ViewGroup.MarginLayoutParams) lp).rightMargin += marRight;//增高
            ((ViewGroup.MarginLayoutParams) lp).bottomMargin += marBottom;//增高
        }
        view.setLayoutParams(lp);
    }

    /***增加 View Margin*/
    public static void addMarginDp(View view, int marLeft, int marTop, int marRight, int marBottom) {
        ViewGroup.LayoutParams lp = view.getLayoutParams();
        if (lp instanceof ViewGroup.MarginLayoutParams) {
            ((ViewGroup.MarginLayoutParams) lp).leftMargin += SizeUtils.dp2px(marLeft);//增高
            ((ViewGroup.MarginLayoutParams) lp).topMargin += SizeUtils.dp2px(marTop);//增高
            ((ViewGroup.MarginLayoutParams) lp).rightMargin += SizeUtils.dp2px(marRight);//增高
            ((ViewGroup.MarginLayoutParams) lp).bottomMargin += SizeUtils.dp2px(marBottom);//增高
        }
        view.setLayoutParams(lp);
    }

    /***增加 View Padding*/
    public static void addPadding(View view, int padLeft, int padTop, int padRight, int padBottom) {
        view.setPadding(padLeft, padTop, padRight, padBottom);
    }


    //    /***跳转View*/
    public static void go(Context context, Class c, Bundle bundle) {
        Intent intent = new Intent(CacheKit.APP_CONTEXT, c);
        if (bundle == null) {
            bundle = new Bundle();
        }
        intent.putExtras(bundle);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        CacheKit.APP_CONTEXT.startActivity(intent);
    }

    //    /***跳转View*/
    public static void go(Activity c) {
        Intent intent = new Intent(CacheKit.APP_CONTEXT, c.getClass());
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        CacheKit.APP_CONTEXT.startActivity(intent);
    }


    //    /***跳转View*/
    public static void go(Class c) {
        Intent intent = new Intent(CacheKit.APP_CONTEXT, c);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        CacheKit.APP_CONTEXT.startActivity(intent);
    }

    //    /***跳转View*/
    public static void goDh(Activity activity, Class c) {
        Intent intent = new Intent(activity.getApplicationContext(), c);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        CacheKit.APP_CONTEXT.startActivity(intent);
        activity.overridePendingTransition(R.anim.slide_right_in, R.anim.slide_left_out);
    }

    //    /***跳转View*/
    public static void goDh(Activity activity, Class c, Bundle bundle) {
        Intent intent = new Intent(activity.getApplicationContext(), c);
        intent.putExtras(bundle);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        CacheKit.APP_CONTEXT.startActivity(intent);
        activity.overridePendingTransition(R.anim.slide_right_in, R.anim.slide_left_out);
    }

    //    /***跳转View*/
    public static void goCloseDh(Activity activity) {
        activity.overridePendingTransition(R.anim.join_to_left, R.anim.close_to_right);
    }

    //    /***跳转View*/
    public static void go(Context context, Class c) {
        Intent intent = new Intent(CacheKit.APP_CONTEXT, c);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        CacheKit.APP_CONTEXT.startActivity(intent);
    }

    //    /***跳转View*/
    public static void go(Class c, Bundle bundle) {
        Intent intent = new Intent(CacheKit.APP_CONTEXT, c);
        if (bundle == null) {
            bundle = new Bundle();
        }
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.putExtras(bundle);
        CacheKit.APP_CONTEXT.startActivity(intent);
    }

    //    /***跳转View 接收 Activity 返回参数*/
    public static void goResult(Activity activity, Class c, Bundle bundle, int code) {
        Intent intent = new Intent(CacheKit.APP_CONTEXT, c);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        if (bundle == null) {
            bundle = new Bundle();
        }
        intent.putExtras(bundle);
        activity.startActivityForResult(intent, code);
    }

    //    /***跳转View 接收 Activity 返回参数*/
    public static void goResultFragment(Activity activity, Class c, Bundle bundle, int code) {
        Intent intent = new Intent(CacheKit.APP_CONTEXT, c);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        if (bundle == null) {
            bundle = new Bundle();
        }
        Fragment fragment;
        intent.putExtras(bundle);
        activity.startActivityForResult(intent, code);
    }

    //    /***Activity 返回参数给YouXuan*/
    public static void returnResultYouXuan(Activity activity, Bundle bundle, int code) {
        Intent intent = new Intent();
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        if (bundle == null) {
            bundle = new Bundle();
            bundle.putInt("biaoji", 99);
        }
        intent.putExtras(bundle);
        activity.setResult(code, intent);
    }

    //    /***Activity 返回参数给*/
    public static void returnResultToActivity(Activity activity, Bundle bundle, int code) {
        Intent intent = new Intent();
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        if (bundle == null) {
            bundle = new Bundle();
        }
        intent.putExtras(bundle);
        activity.setResult(code, intent);
    }

    //    /****打开确认对话框  正方形 确认 取消**/
    public static OpenIsOk_2_Dialog openDialog_2(String title, String content,
                                                 String leftBt, String rightBt, Context activity,
                                                 View.OnClickListener onLeftLinser,
                                                 View.OnClickListener onRightLinser) {
        OpenIsOk_2_Dialog openDialog = new OpenIsOk_2_Dialog(activity.getApplicationContext());
        openDialog.setContent(title, content, leftBt, rightBt);
        openDialog.getOpen_bt1().setOnClickListener(onLeftLinser);
        openDialog.getOpen_bt2().setOnClickListener(onRightLinser);
        openDialog.setCancelable(false);
        openDialog.show();
        return openDialog;
    }


    //    /****打开确认对话框   圆形确认取消 **/
    public static OpenIsOk_1_Dialog openDialog_1(String content, Context activity, View.OnClickListener onRightLinser) {
        OpenIsOk_1_Dialog openDialog = new OpenIsOk_1_Dialog(activity.getApplicationContext());
        openDialog.setContent(content);
        openDialog.getBack().setOnClickListener(onRightLinser);
        openDialog.setCancelable(false);
        openDialog.show();
        return openDialog;
    }


    public static View getView(int layoutId) {
        View dialogView = LayoutInflater.from(CacheKit.APP_CONTEXT).inflate(layoutId, null);
        return dialogView;
    }

    //    /****可点击 不可编辑  隐藏光标**/
    public static void setEditHide(EditText editText) {
        editText.setCursorVisible(false);
        editText.setFocusable(false);
        editText.setFocusableInTouchMode(false);
    }

    //    /****可以编辑 可以点击 显示光标**/
    public static void setEditShow(EditText editText) {
        editText.setFocusable(true);
        editText.setCursorVisible(true);
        editText.setFocusableInTouchMode(true);
        editText.requestFocus();
    }

    //    /****可以编辑 可以点击 显示光标**/
    public static void setFocusShow(EditText editText) {
        editText.setFocusable(true);
        editText.setCursorVisible(true);
        editText.setFocusableInTouchMode(true);
        editText.requestFocus();
    }

    //    /****可以编辑 可以点击 显示光标**/
    public static void setFocusHide(EditText editText) {
        editText.setCursorVisible(false);
        editText.setFocusable(false);
        editText.setFocusableInTouchMode(false);
    }

    //    request failed , reponse's code is : 401
    public static String getCode(Exception e) {
        try {
            String message = e.getMessage();
            String[] split = message.split(":");
            String code = split[(split.length - 1)];
            return code.trim();
        } catch (Exception ee) {
            LogKit.E("  ee ", "  " + ee.getMessage());
            return "";
        }

    }

    //    /****删除线*/
    public static void setTextDelete(TextView text) {
        RxTextTool.getBuilder(text.getText().toString()).setStrikethrough().setAlign(Layout.Alignment.ALIGN_CENTER).into(text);
    }

    //    /****粗体*/
    public static void setTextBlob(TextView text) {
        RxTextTool.getBuilder(text.getText().toString()).setBold().into(text);
    }

    //    /****粗斜体*/
    public static void setTextBoldItalic(TextView text) {
        RxTextTool.getBuilder(text.getText().toString()).setBoldItalic().into(text);
    }

    //    /****斜体*/
    public static void setTextItalic(TextView text) {
        RxTextTool.getBuilder(text.getText().toString()).setItalic().into(text);
    }

    //    /****下划线*/
    public static void setTextUnderline(TextView text) {
        RxTextTool.getBuilder(text.getText().toString()).setUnderline().into(text);
    }

    //    /****字体模糊*/
    public static void setTextBlur(TextView text, int radius) {
        RxTextTool.getBuilder(text.getText().toString()).setBlur(radius, BlurMaskFilter.Blur.NORMAL).into(text);
//
    }

    public static int getColor(int color_id) {
        return ContextCompat.getColor(CacheKit.APP_CONTEXT, color_id);
    }

    //打开商品规格
    public static void openGuiGe(AppCompatActivity activity,
                                 int goodId, String openType, Boolean OutCancel, Boolean Cancelable) {
        GuiGeDialogFragment.init(goodId, openType)
                .setShowBottom(true)
                .show(activity.getSupportFragmentManager())
                .setOutCancel(OutCancel)
                .setOutCancel(OutCancel)
                .setCancelable(Cancelable);
    }

    //打开商品规格
    public static void openGuiGe(AppCompatActivity activity, int goodId,
                                 String openType, Boolean OutCancel, Boolean Cancelable,
                                 GuiGeDialogFragment.GuGeResponseLinster linster) {
        GuiGeDialogFragment.init(goodId, openType, linster)
                .setShowBottom(true)
                .show(activity.getSupportFragmentManager())
                .setOutCancel(OutCancel)
                .setOutCancel(OutCancel)
                .setCancelable(Cancelable);
    }

    //打开商品规格
    public static void openGuiGeTrue(AppCompatActivity activity,
                                     int goodId, String openType) {
        GuiGeDialogFragment.init(goodId, openType)
                .setShowBottom(true)
                .show(activity.getSupportFragmentManager())
                .setOutCancel(true)
                .setOutCancel(true)
                .setCancelable(true);
    }

    //打开商品规格
    public static void openGuiGeTrue(AppCompatActivity activity, int goodId,
                                     String openType,
                                     GuiGeDialogFragment.GuGeResponseLinster linster) {
        GuiGeDialogFragment.init(goodId, openType, linster)
                .setShowBottom(true)
                .show(activity.getSupportFragmentManager())
                .setOutCancel(true)
                .setOutCancel(true)
                .setCancelable(true);
    }

    //打开商品规格
    public static void openGuiGeFalse(AppCompatActivity activity,
                                      int goodId, String openType) {
        GuiGeDialogFragment.init(goodId, openType)
                .setShowBottom(true)
                .show(activity.getSupportFragmentManager())
                .setOutCancel(false)
                .setOutCancel(false)
                .setCancelable(false);
    }

    //打开商品规格
    public static void openGuiGeFalse(AppCompatActivity activity, int goodId,
                                      String openType,
                                      GuiGeDialogFragment.GuGeResponseLinster linster) {
        GuiGeDialogFragment.init(goodId, openType, linster)
                .setShowBottom(true)
                .show(activity.getSupportFragmentManager())
                .setOutCancel(false)
                .setOutCancel(false)
                .setCancelable(false);
    }

    //打开分享
    public static void openShareBottom(AppCompatActivity activity) {
        if (activity != null) {
            ShareDialogFragment shareDialogFragment = new ShareDialogFragment();
            shareDialogFragment.setShowBottom(true);
            shareDialogFragment.show(activity.getSupportFragmentManager());
        }
    }

    //返回星号手机号
    public static String phoneXing(String receiver_tel) {
        String substring = receiver_tel.substring(0, 4);
        String substring1 = receiver_tel.substring(receiver_tel.length() - 4, receiver_tel.length());
        return substring + "****" + substring1;
    }

    //返回星号手机号
    public static void payByNow(JSONObject jsonObject, OrderDownActivity orderDownActivity) {
        JSONObject object = (JSONObject) jsonObject.get("object");
        JSONObject prepay = (JSONObject) object.get("prepay");
        BigDecimal amount = DecimalKit.getDecimal(object.getDouble("amount"));
        String aPackage = prepay.getString("package");// Sign=WXPay
        String appid = prepay.getString("appid");// wxf6dde5dac417893a
        String sign = prepay.getString("sign");//58BC2523E9C94DCD632063D618410B12
        String partnerid = prepay.getString("partnerid");// 1498985912
        String prepayid = prepay.getString("prepayid");// wx15141336908832b9fe7e6aab3097172181
//        wxf6dde5dac417893a
        String noncestr = prepay.getString("noncestr");//BA5TUuWEjgwVVXxYItCietG3qDXOPvX8
        String timestamp = prepay.getString("timestamp");//1529043216
//         = CONST.WEIXIN_APP_ID;
        WechatPayTools.wechatPayApp(CacheKit.APP_CONTEXT,
                appid, //微信分配的APP_ID
                partnerid, //微信分配的 PARTNER_ID (商户ID)
                sign, //微信分配的 PRIVATE_KEY (私钥)
                prepayid, //订单ID (唯一)
                new OnRequestListener() {
                    @Override
                    public void onSuccess(String s) {
                        LogKit.E(" payByNow---> onSuccess ", "  " + s);
//                        orderDownActivity.payErro(s);
                    }

                    @Override
                    public void onError(String s) {
                        LogKit.E(" payByNow---> onSuccess ", "  " + s);
//                        orderDownActivity.paySuccess(s);

                    }
                });
    }


    public static void setSleep(View view, long waitTime) {
        if (view != null) {
            view.setEnabled(false);
        }
        CountDownTimer timer = new CountDownTimer(waitTime, 1000) {
            public void onTick(long millisUntilFinished) {
            }

            public void onFinish() {
                if (view != null) {
                    view.setEnabled(true);
                }
            }
        };
        timer.start();
    }

    public static void setSleep1000(View view) {
        long waitTime = 1000;
        if (view != null) {
            view.setEnabled(false);
        }
        CountDownTimer timer = new CountDownTimer(waitTime, 1000) {
            public void onTick(long millisUntilFinished) {
            }

            public void onFinish() {
                if (view != null) {
                    view.setEnabled(true);
                }
            }
        };
        timer.start();
    }

    public static void setSleep500(View view) {
        long waitTime = 500;
        if (view != null) {
            view.setEnabled(false);
        }
        CountDownTimer timer = new CountDownTimer(waitTime, 1000) {
            public void onTick(long millisUntilFinished) {
            }

            public void onFinish() {
                if (view != null) {
                    view.setEnabled(true);
                }
            }
        };
        timer.start();
    }

    public static void setSleep2000(View view) {
        long waitTime = 2000;
        if (view != null) {
            view.setEnabled(false);
        }
        CountDownTimer timer = new CountDownTimer(waitTime, 1000) {
            public void onTick(long millisUntilFinished) {
            }

            public void onFinish() {
                if (view != null) {
                    view.setEnabled(true);
                }
            }
        };
        timer.start();
    }

    public static void setSleep3000(View view) {
        long waitTime = 3000;
        if (view != null) {
            view.setEnabled(false);
        }
        CountDownTimer timer = new CountDownTimer(waitTime, 1000) {
            public void onTick(long millisUntilFinished) {
            }

            public void onFinish() {
                if (view != null) {
                    view.setEnabled(true);
                }
            }
        };
        timer.start();
    }

    public static void setSleep5000(View view) {
        long waitTime = 5000;
        if (view != null) {
            view.setEnabled(false);
        }
        CountDownTimer timer = new CountDownTimer(waitTime, 1000) {
            public void onTick(long millisUntilFinished) {
            }

            public void onFinish() {
                if (view != null) {
                    view.setEnabled(true);
                }
            }
        };
        timer.start();
    }

    public static void setSleep10000(View view) {
        long waitTime = 10000;
        if (view != null) {
            view.setEnabled(false);
        }
        CountDownTimer timer = new CountDownTimer(waitTime, 1000) {
            public void onTick(long millisUntilFinished) {
            }

            public void onFinish() {
                if (view != null) {
                    view.setEnabled(true);
                }
            }
        };
        timer.start();
    }

    public static void setBackgroundColor(View v, String strColor) {
        if (strColor != null && v != null) {
            if (strColor.length() == 6 || strColor.length() == 7) {
                String color_ = strColor;
                if (color_.contains("#")) {
                } else {
                    color_ = "#" + color_;
                }
                v.setBackgroundColor(Color.parseColor(color_));
            }
        }
    }

    public static void setTextColor(TextView v, String color) {

        if (color != null && v != null) {
            if (color.length() == 6 || color.length() == 7) {
                String color_ = color;
                if (color_.contains("#")) {
                } else {
                    color_ = "#" + color_;
                }
                LogKit.E("setTextColor ---->   ", "  " + color_);
                v.setTextColor(Color.parseColor(color_));
            }

        }
    }

    public static void setTextColor(TextView v, int strColor) {
        v.setTextColor(CacheKit.APP_CONTEXT.getResources().getColor(strColor));
    }

    public static boolean copyText(String s) {
        try {
            //获取剪贴板管理器：
            ClipboardManager cm = (ClipboardManager) CacheKit.APP_CONTEXT.getSystemService(Context.CLIPBOARD_SERVICE);
// 创建普通字符型ClipData
            ClipData mClipData = ClipData.newPlainText("复制完成", s);
// 将ClipData内容放到系统剪贴板里。
            cm.setPrimaryClip(mClipData);
        } catch (Exception e) {
            return false;
        }
        return true;
    }

    public static void daoJishi(final LinearLayout linearLayout, final TextView textView, long waitTime, long interval,
                                final String hint, int backColor1, int textColor1, int backColor2, int textColor2) {
        if (textView != null) {
            textView.setEnabled(false);
            linearLayout.setEnabled(false);

            setTextColor(textView, textColor1);
            linearLayout.setBackgroundResource(backColor1);

        }
        CountDownTimer timer = new CountDownTimer(waitTime, interval) {
            public void onTick(long millisUntilFinished) {
                if (textView != null) {
                    textView.setText(millisUntilFinished / 1000L + " S");
                }
            }

            public void onFinish() {
                if (textView != null && linearLayout != null) {
                    textView.setEnabled(true);
                    linearLayout.setEnabled(true);
                    setTextColor(textView, textColor2);
                    linearLayout.setBackgroundResource(backColor2);
                    textView.setText(hint);
                }

            }
        };
        timer.start();
    }

    public static void daoJishi(final LinearLayout linearLayout, final TextView textView,
                                long waitTime, long interval, final String hint) {
        if (textView != null) {
            textView.setEnabled(false);
            linearLayout.setEnabled(false);

        }
        CountDownTimer timer = new CountDownTimer(waitTime, interval) {
            public void onTick(long millisUntilFinished) {
                if (textView != null) {
                    textView.setText(millisUntilFinished / 1000L + " S");
                }
            }

            public void onFinish() {
                if (textView != null) {
                    textView.setEnabled(true);
                    linearLayout.setEnabled(true);
                    textView.setText(hint);
                }

            }
        };
        timer.start();
    }

    public static void daoJishi(final TextView textView, long waitTime,
                                long interval, final String hint) {
        textView.setEnabled(false);
        CountDownTimer timer = new CountDownTimer(waitTime, interval) {
            public void onTick(long millisUntilFinished) {
                textView.setText(millisUntilFinished / 1000L + " S");
            }

            public void onFinish() {
                textView.setEnabled(true);
                textView.setText(hint);
            }
        };
        timer.start();
    }

    /**
     * RecyclerView 已滑动的距离
     */
    public static int getRecyScrollHeight(RecyclerView mRecyclerView) {
        LinearLayoutManager layoutManager = (LinearLayoutManager) mRecyclerView.getLayoutManager();
        int position = layoutManager.findFirstVisibleItemPosition();
        View firstVisiableChildView =
                layoutManager.findViewByPosition(position);
        int itemHeight = firstVisiableChildView.getHeight();
        int i4 = (position) * itemHeight - firstVisiableChildView.getTop();
        return i4;

//        LinearLayoutManager layoutManager = (LinearLayoutManager) mRecyclerView.getLayoutManager();
//        View firstVisibItem = mRecyclerView.getChildAt(0);
//        int firstItemPosition = layoutManager.findFirstVisibleItemPosition();
//        int itemCount = layoutManager.getItemCount();
//        int recycleViewHeight = mRecyclerView.getHeight();
//        int itemHeight = firstVisibItem.getHeight();
//        int firstItemBottom = layoutManager.getDecoratedBottom(firstVisibItem);
//        return (firstItemPosition + 1) * itemHeight - firstItemBottom;
    }

    /**
     * 还能向下滑动多少
     */
    public static int getRecyScrollShengYu(RecyclerView mRecyclerView) {
        LinearLayoutManager layoutManager = (LinearLayoutManager) mRecyclerView.getLayoutManager();
        View firstVisibItem = mRecyclerView.getChildAt(0);
        int firstItemPosition = layoutManager.findFirstVisibleItemPosition();
        int itemCount = layoutManager.getItemCount();
        int recycleViewHeight = mRecyclerView.getHeight();
        int itemHeight = firstVisibItem.getHeight();
        int firstItemBottom = layoutManager.getDecoratedBottom(firstVisibItem);
        return (itemCount - firstItemPosition - 1) * itemHeight - recycleViewHeight + firstItemBottom;
    }


    /**
     * 判断滑到最底部
     */
    private int getRecyScrollIsEnd(RecyclerView mRecyclerView) {
        LinearLayoutManager layoutManager = (LinearLayoutManager) mRecyclerView.getLayoutManager();
        View firstVisibItem = mRecyclerView.getChildAt(0);
        int firstItemPosition = layoutManager.findFirstVisibleItemPosition();
        int itemCount = layoutManager.getItemCount();
        int recycleViewHeight = mRecyclerView.getHeight();
        int itemHeight = firstVisibItem.getHeight();
        int firstItemBottom = layoutManager.getDecoratedBottom(firstVisibItem);
        return (itemCount - firstItemPosition - 1) * itemHeight - recycleViewHeight;
    }

    public static void setRadioDrawableRight(View view, int id) {
        Drawable drawable = CacheKit.APP_CONTEXT.getResources().getDrawable(id);
        drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());//设置图片展示大小
        ((RadioButton) view).setCompoundDrawables(null, null, drawable, null);
    }

    public static BigDecimal getTwoNumber(double d1, double d2) {
        BigDecimal div = DecimalKit.div(d1, d2);
        return DecimalKit.mul0(div.doubleValue(), 100);
    }

    public static void backHome(Activity activity) {
        Intent intent = new Intent(Intent.ACTION_MAIN);//指定跳到系统桌面,*ACTION_MAIN：应用程序入口点
        intent.addCategory(Intent.CATEGORY_HOME);//*CATEGORY_HOME：随系统启动而运行
        //setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); //清除上一步缓存
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);//*FLAG_ACTIVITY_NEW_TASK：默认的跳转类型,会重新创建一个新的Activity
        activity.startActivity(intent);
    }

    public static void notification(Context context, Intent intent) {
//         *  创建通知栏管理工具
        NotificationManager notificationManager = (NotificationManager) CacheKit.APP_CONTEXT.getSystemService(NOTIFICATION_SERVICE);
//         *  实例化通知栏构造器
        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(CacheKit.APP_CONTEXT, "100");
        PendingIntent pendingIntent = PendingIntent.getActivity(CacheKit.APP_CONTEXT, 0, intent, 0);
        mBuilder.setContentTitle("我是标题")//设置标题
                .setContentText("我是内容")//设置内容
//                .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher))  //设置大图标
                .setSmallIcon(R.mipmap.lymr)      //设置小图标
                .setWhen(System.currentTimeMillis())//设置通知时间
                .setTicker("我是测试内容")//首次进入时显示效果
                .setContentIntent(pendingIntent)
                .setDefaults(Notification.DEFAULT_SOUND);//设置通知方式，声音，震动，呼吸灯等效果，这里通知方式为声音
        notificationManager.notify(10, mBuilder.build());  //发送通知请求
    }

    //展示最后一页状态
    public static void showLastPage(SmartRefreshLayout storyRefreshLayout, boolean isShow) {
        storyRefreshLayout.finishLoadMore();
        storyRefreshLayout.finishRefresh();
        storyRefreshLayout.setEnableLoadMore(false);
        if (isShow) {
            ToastUtils.showShort("已经是最后一页");
        }
        storyRefreshLayout.setEnableRefresh(true);
    }

    //设置 控件 为 可以刷新状态
    public static void openRef(SmartRefreshLayout storyRefreshLayout) {
        storyRefreshLayout.finishLoadMore();
        storyRefreshLayout.setEnableLoadMore(false);
        storyRefreshLayout.setEnableRefresh(true);
    }

    //设置 控件 为 可以加载状态
    public static void openLoad(SmartRefreshLayout storyRefreshLayout) {
        storyRefreshLayout.finishRefresh();
        storyRefreshLayout.setEnableRefresh(false);
        storyRefreshLayout.setEnableLoadMore(true);
    }

    //设置 控件 为 正常状态
    public static void openNormal(SmartRefreshLayout storyRefreshLayout) {
        storyRefreshLayout.setEnableLoadMore(true);
        storyRefreshLayout.setEnableRefresh(true);
        storyRefreshLayout.finishLoadMore();
        storyRefreshLayout.finishRefresh();
    }

    //设置 控件 为 关闭状态
    public static void closeNormal(SmartRefreshLayout storyRefreshLayout) {
        storyRefreshLayout.finishRefresh();
        storyRefreshLayout.finishLoadMore();
        storyRefreshLayout.setEnableLoadMore(false);
        storyRefreshLayout.setEnableRefresh(false);
    }

    //    /*** 过度动画，其实界面，结束界面，两个界面view对应id一样**/
    public static void dongHua(Activity startActivity, Class c, View... views) {
        Intent intent = new Intent(startActivity.getApplicationContext(), c);
        EasyTransitionOptions options =
                EasyTransitionOptions.makeTransitionOptions(
                        startActivity, views);
        EasyTransition.startActivity(intent, options);
    }

    //    /*** 过度动画，其实界面，结束界面，两个界面view对应id一样**/
    public static void dongHua(Activity startActivity, Class c, Bundle bundle, View... views) {
        Intent intent = new Intent(startActivity, c);
        if (bundle != null) {
            intent.putExtras(bundle);
        }
        EasyTransitionOptions options =
                EasyTransitionOptions.makeTransitionOptions(
                        startActivity, views);
        EasyTransition.startActivity(intent, options);
    }

    //    /*** 过度动画，其实界面，结束界面，两个界面view对应id一样**/
    public static void dongHua(Activity startActivity, Class c, Bundle bundle) {
        Intent intent = new Intent(startActivity.getApplicationContext(), c);
        if (bundle != null) {
            intent.putExtras(bundle);
        }
        startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(startActivity).toBundle());
    }

    //删除指定TAG请求
    public static void deleteOKHttp(Object object) {
        if (object != null) {
            OkGo.getInstance().cancelTag(object);
        }
    }

    public static void showView(View v) {
        if (v != null) {
            v.setVisibility(View.VISIBLE);
        }
    }

    public static void hideView(View v) {
        if (v != null) {
            v.setVisibility(View.GONE);
        }
    }

    //注册服务
    public static void registered(Object subscriber) {
        if (!EventBus.getDefault().isRegistered(subscriber)) {
            EventBus.getDefault().register(subscriber);
        }
    }

    //解除注册
    public static void unregister(Object subscriber) {
        if (EventBus.getDefault().isRegistered(subscriber)) {
            EventBus.getDefault().unregister(subscriber);
        }
    }

    //发送普通事件
    public static void sendMessage(Object o) {
        EventBus.getDefault().post(o);
    }

    //判断是否有网络
    public static boolean isInternet() {
        return RxNetTool.isAvailable(CacheKit.APP_CONTEXT);
    }

    //用来切割图片
    public static RequestOptions gildeOptions() {
        RequestOptions options = new RequestOptions();
        options.fitCenter().override(SizeUtils.dp2px(400), SizeUtils.dp2px(400));
        return options;
    }

    //
    public static void setStars(int starCount, ImageView... v) {
        if (v != null) {
            if (v.length == 5) {
                setBackImg(R.mipmap.huisexx, v[0]);
                setBackImg(R.mipmap.huisexx, v[1]);
                setBackImg(R.mipmap.huisexx, v[2]);
                setBackImg(R.mipmap.huisexx, v[3]);
                setBackImg(R.mipmap.huisexx, v[4]);
                switch (starCount) {
                    case 1:
                        setBackImg(R.mipmap.hongsexx, v[0]);

                        break;
                    case 2:
                        setBackImg(R.mipmap.hongsexx, v[0]);
                        setBackImg(R.mipmap.hongsexx, v[1]);
                        break;
                    case 3:
                        setBackImg(R.mipmap.hongsexx, v[0]);
                        setBackImg(R.mipmap.hongsexx, v[1]);
                        setBackImg(R.mipmap.hongsexx, v[2]);
                        break;
                    case 4:
                        setBackImg(R.mipmap.hongsexx, v[0]);
                        setBackImg(R.mipmap.hongsexx, v[1]);
                        setBackImg(R.mipmap.hongsexx, v[2]);
                        setBackImg(R.mipmap.hongsexx, v[3]);
                        break;
                    case 5:
                        setBackImg(R.mipmap.hongsexx, v[0]);
                        setBackImg(R.mipmap.hongsexx, v[1]);
                        setBackImg(R.mipmap.hongsexx, v[2]);
                        setBackImg(R.mipmap.hongsexx, v[3]);
                        setBackImg(R.mipmap.hongsexx, v[4]);
                        break;
                    default:
                        break;
                }
//                v[0].setScaleType(ImageView.ScaleType.CENTER_CROP);
//                v[1].setScaleType(ImageView.ScaleType.CENTER_CROP);
//                v[2].setScaleType(ImageView.ScaleType.CENTER_CROP);
//                v[3].setScaleType(ImageView.ScaleType.CENTER_CROP);
//                v[4].setScaleType(ImageView.ScaleType.CENTER_CROP);
            }
        }
    }

    public static void setText(TextView view, Object s1) {
        if (view != null) {
            if (s1 != null) {
                view.setText(s1.toString());
            }
        }
    }

    public static void setText(TextView view, Object s1, Object s2) {
        if (view != null) {
            if (s1 != null) {
                if (s2 != null) {
                    view.setText(s1.toString() + s2.toString());
                }
            }
        }
    }

    public static void setText(TextView view, Object s1, Object s2, Object s3) {
        if (view != null) {
            if (s1 != null) {
                if (s2 != null) {
                    if (s3 != null) {
                        view.setText(s1.toString() + s2.toString() + s3.toString());

                    }
                }
            }
        }
    }

    public static void setText(TextView view, Object s1, Object s2, Object s3, Object s4) {
        if (view != null) {
            if (s1 != null) {
                if (s2 != null) {
                    if (s3 != null) {
                        if (s4 != null) {
                            view.setText(s1.toString() + s2.toString() + s3.toString() + s4.toString());
                        }
                    }

                }
            }
        }
    }

    public static void setVideo(MyJiaoZiVideo mVideo, Object s_background_video) {
        if (mVideo != null && s_background_video != null) {
            mVideo.setUp(s_background_video.toString(), JZVideoPlayerStandard.SCREEN_WINDOW_NORMAL);
        }

    }

    public static void setVideoImg(MyJiaoZiVideo mVideo, Object s_background_image) {
        if (mVideo != null && s_background_image != null) {
            ImageView thumbImageView = mVideo.thumbImageView;
            thumbImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
            ToolsKit.setImg(thumbImageView, s_background_image.toString(), thumbImageView);
        }

    }
}
